
import Head from 'next/head'

<Head>
  <script>
    {
      `(function() {
         var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e60fb290e204e04c5cb6f79b0ac1e697";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
       })();`
    }
  </script>
</Head>

![LangChain](https://pica.zhimg.com/50/v2-56e8bbb52aa271012541c1fe1ceb11a2_r.gif)






如何使用 PredictionGuard wrapper
=================================================

```python
! pip install predictionguard langchain

```

```python
import predictionguard as pg
from langchain.llms import PredictionGuard

```

基本的LLM用法[#](#basic-llm-usage "Permalink to this headline")
-----------------------------------------------------------------

```python
pgllm = PredictionGuard(name="default-text-gen", token="<your access token>")

```

```python
pgllm("Tell me a joke")

```

链[#](#chaining "Permalink to this headline")
---------------------------------------------------

```python
from langchain import PromptTemplate, LLMChain

```

```python
template = """Question: {question}

Answer: Let's think step by step."""
prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=pgllm, verbose=True)

question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.predict(question=question)

```

```python
template = """Write a {adjective} poem about {subject}."""
prompt = PromptTemplate(template=template, input_variables=["adjective", "subject"])
llm_chain = LLMChain(prompt=prompt, llm=pgllm, verbose=True)

llm_chain.predict(adjective="sad", subject="ducks")

```

